import redis
import importlib
import sys
importlib.reload(sys)
import json

def get_code(unique_code):

    pool= redis.ConnectionPool(host='10.21.32.3', port=6379, db=1,password='63KxsHOY4g939Apq')

    r = redis.Redis(connection_pool=pool)
    keys = r.keys()#获取键
    print(keys)

    # uni="PICTURE_CODE_FOR_ACCOUNT_lOGIN_" + unique_code
    uni="PICTURE_CODE_FOR_ACCOUNT_lOGIN:"+unique_code
    # uni="ff1576121bf5cc1aa8ad97aabdc45be2286a88f5"
    print(uni)
    # print(type(uni))
    # k1=r.get(uni)
    # print(k1)
    # k2=r.get('ff1576121bf5cc1aa8ad97aabdc45be2286a88f5')
    # print(k2)

    k1=r.get(uni).decode()
    # return(k1)

    return eval(k1)['check_code']


    #批量读取数据s

def get_mobile_code(phone):
    # mobile_code = self.conn.get('MOBILE_CODE_FOR_USER_ID_' + phone)
    # pool= redis.ConnectionPool(host='10.21.32.3', port=6379, db=1,password='63KxsHOY4g939Apq')
    #
    # conn= redis.Redis(connection_pool=pool)

    conn = redis.Redis(host='10.21.32.3',
                            port=6379,
                            db=1,
                            password='63KxsHOY4g939Apq')

    mobile_code = conn.get('sms:code:' + phone)
    if mobile_code:
        mobile_code = mobile_code.decode('utf-8')
        mobile_code = json.loads(mobile_code, encoding='utf-8')['code']
    else:
        print('短信验证码为空')
    conn.close()
    return mobile_code

if __name__=="__main__":
    unique_code="picture_1577332374096157733237409672"
    c=get_code(unique_code)
    print(c)
    # print(type(c))
    # d=get_mobile_code(phone="17653322222")
    # print(d)
